package org.minproject.my_library_back.controller;

import jakarta.annotation.Resource;
import org.minproject.my_library_back.common.CommonResponse;
import org.minproject.my_library_back.domain.Comment;
import org.minproject.my_library_back.domain.User;
import org.minproject.my_library_back.service.CommentService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class CommentController {
    @Resource
    private CommentService commentService;

    @GetMapping("/comments")
    public CommonResponse<List<Comment>>  getComments() throws Exception {
        return commentService.getAllComments();
    }
    @GetMapping("/comments/{id}")
    public CommonResponse<List<Comment>> getCommentsByUserid(@PathVariable("id") int bookid) throws Exception{
        return commentService.getCommentById(bookid);
    }
    @PostMapping("/comments/")
    public CommonResponse<Comment> addComment(@RequestBody Comment comment) throws Exception {
        return commentService.addComment(comment);
    }

    @PostMapping("/comments/{id}")
    public CommonResponse<Comment> deleteComment(@PathVariable("id") int commentid) throws Exception {
        return commentService.deleteComment(commentid);
    }
}
